<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>Slide And Fade</title>
    <style>
        #main1 {
            margin: 20px auto;
            width: 200px;
            background-color: #6c9;
            overflow: hidden;
        }

        .maindiv {
            margin: 20px auto;
            width: 200px;
            background-color: #6c9;
            overflow: hidden;
        }
    </style>
    <script type="text/javascript">
        var Animate = {
            obj: null,
            itime: 0,
            flag: 1,
            maxHeight: 0,
            _$: function (id) {
                return "string" == typeof (id) ? document.getElementById(id) : id;
            },
            slideDown: function (objid, itime, height) {
                this.maxHeight = height;
                this.obj = this._$(objid);
                this.itime = itime;
                if (parseInt($(this.obj).css("height")) > this.maxHeight) {
                    this.flag = 0;
                    return;
                };
                var tempnum = parseInt($(this.obj).css("height")) + 1;
                $(this.obj).css("height", tempnum);
                
                setTimeout(function () { Animate.slideDown(objid, itime, height); }, this.itime);
            },
            slideUp: function (objid, itime) {
                this.obj = this._$(objid);
                this.itime = itime;
                if (parseInt($(this.obj).css("height")) < 1) {
                    this.flag = 1;
                    return;
                };
                var tempnum = parseInt($(this.obj).css("height")) - 1;
                $(this.obj).css("height", tempnum);
                setTimeout(function () { Animate.slideUp(objid, itime); }, this.itime);
            },
            slide: function (objid, itime) {
                this.obj = this._$(objid);
                this.itime = itime;

                if (this.flag) {
                    this.maxHeight = this.maxHeight ? this.maxHeight : parseInt(this.obj.style.height);
                    this.obj.style.display = "block";
                    this.obj.style.height = "0px";
                    this.slideDown();
                }
                else {
                    this.slideUp();
                }
            },
            fadeIn: function (objid, itime) {
                this.obj = this._$(objid);
                this.itime = itime;
                var that = this;
                this.maxHeight = parseInt(this.obj.style.height);
                var i = 100;
                var timer = setInterval(function () {
                    that.obj.style.cssText = "filter :alpha(opacity=" + i + ");-moz-opacity:" + i * 0.01 + ";opacity: " + i * 0.01 + ";height:" + that.maxHeight + "px;";
                    i--;

                    if (i == 0) clearInterval(timer);
                }, that.itime);
            },
            fadeOut: function (objid, itime) {
                this.obj = this._$(objid);
                this.itime = itime;
                var that = this;
                this.maxHeight = parseInt(this.obj.style.height);
                var i = 0;
                var timer = setInterval(function () {
                    that.obj.style.cssText = "filter :alpha(opacity=" + i + ");-moz-opacity:" + i * 0.01 + ";opacity: " + i * 0.01 + ";height:" + that.maxHeight + "px;";
                    i++;
                    if (i == 100) clearInterval(timer);
                }, that.itime);
            }
        }
    </script>
</head>
<body>
    <input type="button" value="slide" onclick="document.getElementById('d1').style.display='block';Animate.slideDown('d1', 6, 200); Animate.slideUp('d2', 6);" />
    <input type="button" value="fadeIn" onclick="Animate.fadeIn('d2', 10)" />
    <input type="button" value="fadeOut" onclick="Animate.fadeOut('d2', 10)" />
    <%--<div id="main1" style="height: 200px;">
        slide && fadeIn && fadeIn && fadeOut 
    </div>--%>

    <div class="maindiv" style="height: 0px;display:none" id="d1">
        slide111.............
    </div>
    <div class="maindiv" style="height: 200px;" id="d2">
        slide222.............
    </div>
</body>
</html>